﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OleDb;
using System.Data.Odbc;
using System.Data.SqlClient;

using ConversaoSIC.VO;

namespace ConversaoSIC.DAL
{
    public class BaseDAL
    {
        public DataSet LerTabela(string pPath, string pQuery)
        {
            try
            {
                OleDbDataAdapter da = ConnectParadox(pPath, pQuery);
                DataSet dsRetrievedData = new DataSet();
                da.Fill(dsRetrievedData);
                da.Dispose();

                return dsRetrievedData;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public OleDbDataAdapter ConnectParadox(string pPath, string pQuery)
        {
            string strConnection = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + pPath + "; Extended Properties=Paradox 5.x";
            try
            {
                OleDbConnection oleConnection = new OleDbConnection(strConnection);
                oleConnection.Open();
                OleDbDataAdapter oleAdapter = new OleDbDataAdapter(pQuery, oleConnection);
                oleConnection.Close();
                return oleAdapter;
            }
            catch (OleDbException e)
            {
                throw e;
            }
        }

        public SqlConnection ConnectSQLServer()
        {
            try
            {
                SqlConnection cn = new SqlConnection("Data Source=localhost; Initial Catalog=dbCentrus;Integrated Security = true;");
                return cn;
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }

    }
}
